package pl.wroc.pwr.docs.repos.domain;

import java.sql.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;

import org.apache.lucene.analysis.standard.StandardFilter;
import org.apache.solr.analysis.HunspellStemFilterFactory;
import org.apache.solr.analysis.LowerCaseFilterFactory;
import org.apache.solr.analysis.StandardFilterFactory;
import org.apache.solr.analysis.StandardTokenizerFactory;
import org.apache.solr.analysis.StopFilterFactory;
import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.AnalyzerDef;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Parameter;
import org.hibernate.search.annotations.TermVector;
import org.hibernate.search.annotations.TokenFilterDef;
import org.hibernate.search.annotations.TokenizerDef;

@Entity
@Table(name = "DOCUMENTS")
@Indexed
@AnalyzerDef(
		name = "polish",
		tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
		filters = {
			@TokenFilterDef(factory = LowerCaseFilterFactory.class),
			@TokenFilterDef(factory = StopFilterFactory.class, params = {
				@Parameter(name = "words", value = "org/apache/lucene/analysis/pl/stopwords.txt"),
				@Parameter(name = "enablePositionIncrements", value = "true"),
				@Parameter(name = "ignoreCase", value = "true")
			}),
			@TokenFilterDef(factory = HunspellStemFilterFactory.class, params = {
				@Parameter(name = "dictionary", value = "pl_PL.dic"),
				@Parameter(name = "affix", value = "pl_PL.aff"),
				@Parameter(name = "ignoreCase", value = "true")
			})
})
public class Document {
	public enum FORMAT { DOC, DOCX, ODT, PDF, RTF, TXT, Inny };
	public static final int MAX_CONTENT_LENGTH = 10000;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO) 
	@Column
	private int id;
	@Column 
	private String filename;
	@Lob
	@Column(name = "BINARY") 
	private byte[] binaryData;
	@Field(termVector = TermVector.YES)
	@Analyzer(definition = "polish")
	@Column(name = "INDEXED_CONTENT", length = MAX_CONTENT_LENGTH)
	private String indexedContent;
	@Field
	@Column
	private FORMAT format;
	@Column
	private Date created;
	@Column
	private Date added;
	@Column
	private String title;
	@Column
	private String author;
	
	// gettery, settery  
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}
	
	public byte[] getBinaryData() {
		return binaryData;
	}
	
	public void setBinaryData(byte[] binaryData) {
		this.binaryData = binaryData;
	}
	
	public String getIndexedContent() {
		return indexedContent;
	}

	public void setIndexedContent(String indexedContent) {
		this.indexedContent = indexedContent;
	}

	public FORMAT getFormat() {
		return format;
	}

	public void setFormat(FORMAT format) {
		this.format = format;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public Date getAdded() {
		return added;
	}

	public void setAdded(Date added) {
		this.added = added;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}
}